<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class Power {
            constructor() {
                this.serveVoltage = 110
                this.serveShape = 'triangle'
            }
        }
        class Adaptor {
            constructor() {
                this.consumeVoltage = 110
                this.consumeShape = 'triangle'
            }
            usePower(power) {
                if (!power) {
                    throw new Error('请接入电源')
                }
                if (power.serveVoltage !== this.consumeVoltage || power.serveShape !== this.consumeShape) {
                    throw new Error('电源规格不对')
                }
                this.serveVoltage = 220
                this.serveShape = 'double'
            }
        }

        class User {
            constructor() {
                this.consumeVoltage = 220
                this.consumeShape = 'double'
            }
            usePower(power) {
                if (!power) {
                    throw new Error('请接入电源')
                }
                if (power.serveVoltage !== this.consumeVoltage || power.serveShape !== this.consumeShape) {
                    throw new Error('电源规格不对')
                }
                console.log('电源已接入');
            }
        }
        let power = new Power()
        let user = new User()
        let adaptor = new Adaptor()
        adaptor.usePower(power)
        user.usePower(adaptor)
    </script>
</body>

</html>